var user;
	var pass;
	var url;
function SceneLogin() {
	url = "http://quangdung.vv.si/main.php";
	var ime = {};
	var element = {}; // input id
	
	var ItemCursor = 0;
	
	this.createIME = function (id) {
		var imeReady = function(imeObject) {
			installStatusCallbacks(imeObject);
			document.getElementById(id).focus();
		};
		ime = new IMEShell(id, imeReady);
		element = document.getElementById( id );
	};
	
	this.init = function () {
		$("#div_obj_" + ItemCursor).css('outline', 'solid 4px #FF4500');
		this.createIME("input_obj_" + ItemCursor);
	};
	
	this.enter = function () {
		element.focus();
	};
	
	this.nextItem = function (dir) {
		$("#div_obj_" + ItemCursor).css('outline', 'solid 1px #666666');
		
		ItemCursor = ItemCursor + dir;
		
		if (ItemCursor < 0) {
			ItemCursor = 3;
		} else if (ItemCursor > 3) {
			ItemCursor = 0
		}
		
		$("#div_obj_" + ItemCursor).css('outline', 'solid 4px #FF4500');
		this.createIME("input_obj_" + ItemCursor);
	};
	
	var onReturnScene = function () {
		element.blur();
	};
	
	var installStatusCallbacks = function(_ime) {
		alert("   installStatusCallbacks. [START]");
		_ime.setOnCompleteFunc(onComplete);		
		_ime.setEnterFunc(onEnter);
		_ime.setKeyFunc(sf.key.RETURN, onReturnScene);
		alert("   installStatusCallbacks. [End] " );
	};
	
	var onComplete = function() {
		alert("onComplete: Letter entry completed in " + element.id + ", text is " + element.value);
		var mode = ['_latin_small', '_latin_big', '_num', '_special'];
		if(ItemCursor==0)
			user = element.value;
			if(ItemCursor==1)
				pass = element.value;
		ime.setMode(mode[ItemCursor]);
		alert("mode[ " + ItemCursor + " ] = " + mode[ItemCursor]);
	};
	
	var onEnter = function(string) {
		alert("  onEnter: Enter key pressed in " + element.id + ", string is " + string);
	};
}

SceneLogin.prototype.initialize = function () {
	alert("SceneLogin.initialize()");
	this.init();
}

SceneLogin.prototype.handleShow = function (data) {
	alert("SceneLogin.handleShow()");
}

SceneLogin.prototype.handleHide = function () {
	alert("SceneLogin.handleHide()");
}

SceneLogin.prototype.handleFocus = function () {
	alert("SceneLogin.handleFocus()");
}

SceneLogin.prototype.handleBlur = function () {
	alert("SceneLogin.handleBlur()");
}
function ok() {
	alert('asd-----------------------');
	//alert('ok'+":"+user.length+":"+pass.length+":"+":"+user+":"+pass+":");	
	if((typeof user == 'undefined')||(typeof pass == 'undefined')){
		$('#Popup_invite_ok').sfPopup({
			text:"Tên dang nh?p ho?c m?t kh?u ph?i trên 6 ký t?",
			buttons:['OK'],
			timeout:50000,
			callback:function(){

	       

	                sf.scene.focus('Login');}


		}).sfPopup('show');
		$("#Popup_invite_ok").css({ top: '100px' });
		$("#Popup_invite_ok").css({ left: '50px' });
	}
	else if(user.length<6 || pass.length<6){
		$('#Popup_invite_ok').sfPopup({
			text:"Tên dang nh?p ho?c m?t kh?u ph?i trên 6 ký t?",
			buttons:['OK'],
			timeout:50000,
			callback:function(){

	       

	                sf.scene.focus('Login');}


		}).sfPopup('show');
		$("#Popup_invite_ok").css({ top: '100px' });
		$("#Popup_invite_ok").css({ left: '50px' });
	}
	else{		
		$.getJSON(url+'?command=login&username='+user+'&password='+pass, function(data) {
			if(data.msg.indexOf("success")!=-1){
				$('#Popup_invite_ok').sfPopup({
					text:data.msg,
					buttons:['OK'],
					timeout:50000,
					callback:function(){

			                //sf.scene.focus('Login');
			                sf.scene.hide('Login');
			    			sf.scene.show('home',"return");
			    			sf.scene.focus('home');
			    			}
				

				}).sfPopup('show');
				$("#Popup_invite_ok").css({ top: '100px' });
				$("#Popup_invite_ok").css({ left: '50px' });
			}
			else{
				$('#Popup_invite_ok').sfPopup({
					text:data.msg,
					buttons:['OK'],
					timeout:50000,
					callback:function(){

			       

			                sf.scene.focus('Login');}


				}).sfPopup('show');
				$("#Popup_invite_ok").css({ top: '100px' });
				$("#Popup_invite_ok").css({ left: '50px' });
			}
			
		});
		
	}
	
}

function cancel() {
	alert('cancel');
	 sf.scene.hide('Login');
		sf.scene.show('home',"return");
		sf.scene.focus('home');
}

SceneLogin.prototype.handleKeyDown = function (keyCode) {
	alert("SceneLogin.handleKeyDown(" + keyCode + ")");
	switch (keyCode) {
		case sf.key.LEFT:
			this.nextItem(-1);
			break;
		case sf.key.RIGHT:
			this.nextItem(+1);
			break;
		case sf.key.UP:
			this.nextItem(-1);
			break;
		case sf.key.DOWN:
			this.nextItem(+1);
			break;
		case sf.key.ENTER:
			this.enter();
			break;
	}
}